<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>测试watch监听</title>
  <!-- 导入完整版的vue文件 -->
  <script src="/node_modules/vue/dist//vue.js"></script>
</head>
<body>
  <div id="app">{{list}}</div>
</body>
<script type="module">
  let vm = new Vue({
    el: '#app',
    data: {
      list: [1, 2, 3, 4, 5],
      name: 'lzc'
    },
    watch: {
      /**
       * 监听的4种写法：
       * 1、函数
       * 2、对象
       * 3、数组
       * 4、字符串
      */
      // list(newVal, oldVal) {
      //   console.log('list==>', newVal);
      // },
      list: {
        // handler(newVal, oldval) {
        //   console.log('list==>', newVal);
        // },
        handler: 'handlerFn',
        immediate: true,
        deep: true
      },
      // list: [
      //   () => { console.log(1); },
      //   () => { console.log(2); },
      // ],
      // list: 'handlerFn'
    },
    mounted() {
      setTimeout(() => {
        this.list.push(6);
      }, 1500)
    },
    methods: {
      handlerFn(newVal, oldval) {
        console.log('list==>', newVal, oldval);
      }
    }
  })
</script>
</html>